/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2010 Benoit Saint-Maxent
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package marcel.events {
	import flash.events.Event;

	/**
	 * Event dispatched by the AsynchCommand and the AsyncMacroCommand classes
	 * @author Benoit Saint-Maxent
	 */
	public class AsyncRequestEvent extends Event {
		
		
		//--------------------------------------------------------------------------
		//
		//  EVENT TYPES
		//
		//--------------------------------------------------------------------------
		
		/**
		 * Dispatched when the asynchronous request has completed successfully
		 * @eventType	result
		 */
		public static const RESULT : String = "result";
		
		/**
		 * Dispatched when the asynchronous request has failed
		 * @eventType	fault
		 */
		public static const FAULT : String = "fault";
		
		/**
		 * Dispatched when the asynchronous request has progressed
		 * @eventType	progress
		 */
		public static const PROGRESS : String = "progress";
		
		
		
		
		//--------------------------------------------------------------------------
		//
		// Public vars
		//
		//--------------------------------------------------------------------------
		
		/**
		 * The percentage of completion of the asynchronous request (0 -> 1)
		 * defined if the current type is PROGRESS
		 */
		public var percent : Number;
		
		/**
		 * The error description when the asynchronous request has failed
		 * defined if the current type is FAULT
		 */
		public var error : Error;
		
		/**
		 * The result of the asynchronous request
		 * defined if the current type is RESULT
		 */
		public var result : *;

		
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		/**
		 * Constructs a new AsyncRequestEvent instance
		 * @param	type		Event type
		 * @param	percent		Percentage of completion (0 -> 1)
		 * @param	result		Result of the request
		 * @param	error		Error description
		 */
		public function AsyncRequestEvent(type : String, percent : Number = 0, result : * = null, error : Error = null) {
			super(type, false, false);
			this.percent = percent;
			this.result = result;
			this.error = error;
		}
		
		
		//--------------------------------------------------------------------------
		//
		//  Public methods
		//
		//--------------------------------------------------------------------------
		
		/**
		 * overriding clone method
		 * @return	a copy of the current AsyncRequestEvent
		 */
		override public function clone() : Event {
			return new AsyncRequestEvent(type, percent, result, error);
		}	
	}
}
